package com.mindskip.xzs.repository;

import com.mindskip.xzs.domain.MessageUser;
import com.mindskip.xzs.repository.base.MyMapper;
import com.mindskip.xzs.viewmodel.student.user.MessageRequestVM;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface MessageUserMapper extends MyMapper<MessageUser> {
//    int deleteByPrimaryKey(Integer id);
//
//    int insert(MessageUser record);
//
//    int insertSelective(MessageUser record);
//
//    MessageUser selectByPrimaryKey(Integer id);
//
//    int updateByPrimaryKeySelective(MessageUser record);
//
//    int updateByPrimaryKey(MessageUser record);

    String queryParams = " id, message_id messageId, receive_user_id receiveUserId, receive_user_name receiveUserName, " +
            "receive_real_name receiveRealName, readed, create_time createTime, read_time readTime ";

    @Select("select " + queryParams +
            "from t_message_user\n" +
            "where  message_id  in" +
            "<foreach item=\"id\" collection=\"ids\" open=\"(\" separator=\",\"  close=\")\">\n" +
            "#{id}\n" +
            "</foreach>")
    List<MessageUser> selectByMessageIds(@Param("ids") List<Integer> ids);

    @Select("select " + queryParams +
            "from t_message_user\n" +
            "where receive_user_id = #{receiveUserId}")
    List<MessageUser> studentPage(MessageRequestVM requestVM);

    @Select("select count(*)\n" +
            "from t_message_user\n" +
            "where  readed='f' and  receive_user_id = #{userId}")
    Integer unReadCount(@Param("userId") Integer userId);
}
